cmake_minimum_required(VERSION 3.2)
project(c_lua_interface)

#头文件目录
set(LUA_INCLUDE ./lua/src)

# 链接库
set(LIB_DIR ./libs)
set(LIB_FILE
    liblua.a
)

link_directories(${LIB_DIR})
# 定义通用静态库
set(COM_LIBS z dl rt pthread)

# 设置编译选项
add_compile_options(-ggdb -Wall -Wextra -pipe -O0 -fPIC -Wno-unused-local-typedefs -Wno-strict-aliasing)

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/luaclib)

#生成tbl.so
add_library(tbl SHARED
        ./lualib-src/lua-tbl.c
)
target_include_directories(tbl PUBLIC ${LUA_INCLUDE})
set_target_properties(tbl PROPERTIES PREFIX "")
target_link_libraries(tbl ${LIB_FILE} ${COM_LIBS})


#生成reg1.so
add_library(reg1 SHARED
        ./lualib-src/lua-reg1.c
)
target_include_directories(reg1 PUBLIC ${LUA_INCLUDE})
set_target_properties(reg1 PROPERTIES PREFIX "")
target_link_libraries(reg1 ${LIB_FILE} ${COM_LIBS})

#生成reg2.so
add_library(reg2 SHARED
        ./lualib-src/lua-reg2.c
)
target_include_directories(reg2 PUBLIC ${LUA_INCLUDE})
set_target_properties(reg2 PROPERTIES PREFIX "")
target_link_libraries(reg2 ${LIB_FILE} ${COM_LIBS})

#生成ud.so
add_library(ud SHARED
        ./lualib-src/lua-ud.c
)
target_include_directories(ud PUBLIC ${LUA_INCLUDE})
set_target_properties(ud PROPERTIES PREFIX "")
target_link_libraries(ud ${LIB_FILE} ${COM_LIBS})

#生成uv.so
add_library(uv SHARED
        ./lualib-src/lua-uv.c
)
target_include_directories(uv PUBLIC ${LUA_INCLUDE})
set_target_properties(uv PROPERTIES PREFIX "")
target_link_libraries(uv ${LIB_FILE} ${COM_LIBS})